import 'dart:convert';

import 'package:android_intent_plus/android_intent.dart';
import 'package:bruno/bruno.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:sph_driver/AppConfig/ShowDialog.dart';
import 'package:sph_driver/Order/EvaluationPage.dart';
import 'package:sph_driver/Order/WaybillDetails/ShipperIntroduction.dart';
import 'package:url_launcher/url_launcher.dart';


import '../../AppConfig/Config.dart';
import '../../AppConfig/LocalStorage.dart';
import '../../AppConfig/RouteAct.dart';
import '../../FindGoods/DrivingRouteView.dart';
import '../../Message/SingleChatPage.dart';
import '../../Tabbar/TabbarView.dart';
import '../../http/NoLoadingGetApi.dart';
import '../../http/getapi.dart';
import '../OrderList/RuningOrderList.dart';
import 'CancelWaybill.dart';
import 'ComplaintService.dart';
import 'DriverIDPhoto.dart';
import 'ElectronicAgreementView.dart';
import 'PayTheFreight.dart';
import 'PictureManagement.dart';
import 'TransportProtocolNodes.dart';
import 'UnconfirmedTransportationAgreement.dart';
import 'UploadPhotoPage.dart';
import 'package:platform/platform.dart';
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
import 'package:platform/platform.dart';
class WaybillDetails extends StatefulWidget {


  const WaybillDetails({super.key, required this.billId, required this.type});
  final String billId;
  final int type;
  @override
  State<WaybillDetails> createState() => _WaybillDetailsState();
}

class _WaybillDetailsState extends State<WaybillDetails> {

  Map dataMap={};
  List orderLogList=[];
  List depositLogList=[];
  List freightLogList=[];
  List serviceLogList=[];
  List protocolLogList=[];
  List trajectoryLogList=[];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    print(widget.billId);
    getbillDetial();
    getOrderLog();

  }
  _makePhoneCall(String phoneNumber) async {
    if (LocalPlatform().isAndroid) {
      var status = await Permission.phone.status;
      if (status.isGranted) {
        // 权限已被授予
        // callPhone();
        final AndroidIntent intent = AndroidIntent(
          action: 'android.intent.action.CALL',
          data: Uri.encodeFull('tel:$phoneNumber'),
        );
        await intent.launch();
      } else if (status.isDenied) {
        showCallPhoneFirstDialog(context);
        // 权限被拒绝，但用户可以再次授权
        status = await Permission.phone.request();
        if (status.isGranted) {
          // 用户同意了权限
          // callPhone();
          final AndroidIntent intent = AndroidIntent(
            action: 'android.intent.action.CALL',
            data: Uri.encodeFull('tel:$phoneNumber'),
          );
          await intent.launch();
        } else {
          showCallPhoneDialog(context);
          // 用户拒绝权限，无法发起电话
          // 可以在此处展示信息提示用户需要权限
        }
      } else if (status.isPermanentlyDenied) {
        // 权限被永久拒绝，需要用户手动开启权限
        showCallPhoneDialog(context);
      }

    }else{
      final url =Uri.parse('tel:$phoneNumber');
      if (await canLaunchUrl(url)) {
        await launchUrl(url);
      } else {
        throw '无法拨打电话：$url';
      }
    }
  }
  void _copyToClipboard(String copyNumber) {
    Clipboard.setData(ClipboardData(text: copyNumber));
    BrnToast.show('复制成功', context);

  }
  //获取详情
  Future<void> getbillDetial() async {
    NoLoadinggetApiManager.getData(
      context,
      'api/waybill/driver/waybill/details',
      {
        "waybillId": widget.billId,
      },
          (responseData) {
        setState(() {
          dataMap=responseData['data'];

        });
      },
    );
  }
//获取运单节点
  Future<void> getOrderLog() async {
    NoLoadinggetApiManager.getData(
      context, // 上下文对象，用于显示提示信息等
      'api/waybill/log/page', // 您的API端点
      {"waybillId": widget.billId,}, // 查询参数，如果没有可以传递null
          (responseData)  {
        setState(() {
        orderLogList=responseData['data']['records'];
        });
      },
    );
  }
  Future<void> refuseAction(int refuseStatus) async {

  }
  Future<void> cancelAction(String waybillId,int cancelStatus) async {

  }
  //同意/拒绝取消运单
  Future<void> cancelComAction(int sureStatus) async {

  }
void choosePageAct(){
  NoLoadinggetApiManager.getData(
    context,
    'api/waybill/driver/waybill/details',
    {
      "waybillId": widget.billId,
    },
        (responseData) {
      setState(() {
        dataMap=responseData['data'];
        if(dataMap['contractStatus']==0||dataMap['contractStatus']==2){
          Navigator.push( context, FadeRoute(page:UnconfirmedTransportationAgreement(wayBillId: dataMap['id'], Type: 1,
          )));
        }else{
          Navigator.push( context, FadeRoute(page:TransportProtocolNodes(waybillId: dataMap['id'],
          )));
        }
      });
    },
  );
}

//查看路线
  void onOpenBaiduNaviNative(BMFNaviType naviType) async {
    // 我的位置
    BMFCoordinate coordinate1 = BMFCoordinate(dataMap['goodsInfo']['loadPlaceInfo'][0]['latitude'],dataMap['goodsInfo']['loadPlaceInfo'][0]['longitude']);
    String startName = dataMap['goodsInfo']['loadPlaceInfo'][0]['address'];
    // 百度大厦坐标
    String endName = dataMap['goodsInfo']['unloadPlaceInfo'][0]['address'];
    BMFCoordinate coordinate2 = BMFCoordinate(dataMap['goodsInfo']['unloadPlaceInfo'][0]['latitude'], dataMap['goodsInfo']['unloadPlaceInfo'][0]['longitude']);
    BMFOpenNaviOption naviOption = BMFOpenNaviOption(
        startCoord: coordinate1,
        endCoord: coordinate2,
        startName: startName,
        endName: endName,
        naviType: naviType,
        appScheme: 'baidumapsdk://mapsdk.baidu.com', // 指定返回自定义scheme
        appName: 'baidumap', // 应用名称
        isSupportWeb:
        false); // 调起百度地图客户端驾车导航失败后（步行、骑行导航设置该参数无效），是否支持调起web地图，默认：true

    BMFOpenErrorCode? flag = await BMFOpenMapUtils.openBaiduMapNavi(naviOption);
    print('open - navi - errorCode = $flag');
  }
  //去装货地
  void onOpenBaiduMapRoute(BMFOpenRouteType routeType) async {
    String? lat= await LatitudeManager.getLatitude();
    String? lon= await LongitudeManager.getLongitude();
    // BMFCoordinate startCoord = BMFCoordinate(double.parse(dataMap['loadPlaceInfo'][0]['latitude']), double.parse(dataMap['loadPlaceInfo'][0]['longitude']));

    BMFCoordinate  startCoord = BMFCoordinate(double.parse(lat!) , double.parse(lon!));

    // String startName = dataMap['loadPlaceInfo'][0]['detailedAddress'];
    String startName ="我的位置";
    String endName =dataMap['goodsInfo']['loadPlaceInfo'][0]['address'];
    BMFCoordinate endCoord = BMFCoordinate(dataMap['goodsInfo']['loadPlaceInfo'][0]['latitude'], dataMap['goodsInfo']['loadPlaceInfo'][0]['longitude']);
    BMFOpenRouteOption routeOption = BMFOpenRouteOption(
        startCoord: startCoord,
        startName: startName,
        endCoord: endCoord,
        endName: endName,
        routeType: routeType,
        appScheme: 'baidumapsdk://mapsdk.baidu.com', // 指定返回自定义scheme
        isSupportWeb: true);
    BMFOpenErrorCode? flag =
    await BMFOpenMapUtils.openBaiduMapRoute(routeOption);
    print('open - route - errorCode = $flag');
  }
  //去卸货地
  void onOpenBaiduMapRouteUnload(BMFOpenRouteType routeType) async {
    String? lat= await LatitudeManager.getLatitude();
    String? lon= await LongitudeManager.getLongitude();
    // BMFCoordinate startCoord = BMFCoordinate(double.parse(dataMap['loadPlaceInfo'][0]['latitude']), double.parse(dataMap['loadPlaceInfo'][0]['longitude']));

    BMFCoordinate  startCoord = BMFCoordinate(double.parse(lat!) , double.parse(lon!));

    // String startName = dataMap['loadPlaceInfo'][0]['detailedAddress'];
    String startName ="我的位置";
    String endName =dataMap['goodsInfo']['unloadPlaceInfo'][0]['address'];
    BMFCoordinate endCoord = BMFCoordinate(dataMap['goodsInfo']['unloadPlaceInfo'][0]['latitude'], dataMap['goodsInfo']['unloadPlaceInfo'][0]['longitude']);
    BMFOpenRouteOption routeOption = BMFOpenRouteOption(
        startCoord: startCoord,
        startName: startName,
        endCoord: endCoord,
        endName: endName,
        routeType: routeType,
        appScheme: 'baidumapsdk://mapsdk.baidu.com', // 指定返回自定义scheme
        isSupportWeb: true);
    BMFOpenErrorCode? flag =
    await BMFOpenMapUtils.openBaiduMapRoute(routeOption);
    print('open - route - errorCode = $flag');
  }
  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    return Scaffold(
      appBar: AppBar(
        title: Text("运单详情",style: TextStyle(fontWeight: FontWeight.w300,fontSize: 16.sp),),
        centerTitle: true,
        backgroundColor: Color.fromRGBO(251,236,228,1),
        leading: IconButton(icon: Icon(Icons.arrow_back_ios,color: Colors.black,),onPressed: (){
          if(widget.type==2){
            Navigator.of(context).pushAndRemoveUntil(
                MaterialPageRoute(builder: (builder) {
                  return TabbarView(pateIndex: 2,);
                }), (route) => route == null);
          }else{
            Navigator.pop(context);
          }

          },),
        // actions: [
        //   GestureDetector(
        //     child: Text("投诉"),
        //     onTap: (){
        //       Navigator.push(context,
        //           MaterialPageRoute(builder: (context) {
        //             return ComplaintService();
        //           }));
        //     },
        //   ),
        //   Badge(label: Text("1"),),
        // ],
      ),
      body:dataMap.isEmpty? Center(
        child:
        LoadingAnimationWidget.prograssiveDots(color: MyColors.themeColor, size: 50),
      ):
      Container(
        decoration: BoxDecoration(
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: [Color.fromRGBO(251,236,228,1),MyColors.backgreyColor, MyColors.backgreyColor],
          ),
        ),
        child:
        Column(
          children: [
            Expanded(child: ListView(
              children: [
                Container(
                  padding: EdgeInsets.only(left: 23.w,right: 45.w),
                  child:  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      GestureDetector(
                        child: Row(
                          children: [
                            if(dataMap['cancelStatus']==1)
                              Text("已取消",style: TextStyle(color: MyColors.themeColor,fontSize: 28.sp,fontWeight: FontWeight.w600),),
                            if(dataMap['deliveryStatus']==1)
                              Text("已完成",style: TextStyle(color: MyColors.themeColor,fontSize: 28.sp,fontWeight: FontWeight.w600),),
                            if(dataMap['contractStatus']==0&&dataMap['cancelStatus']==0 &&dataMap['cancelStatus']!=1)
                              Text(dataMap['mode']=="DRIVER"?"待货主确认":"指派待确认",style: TextStyle(color: MyColors.themeColor,fontSize: 28.sp,fontWeight: FontWeight.w600),),
                            if(dataMap['contractStatus']==2&&dataMap['cancelStatus']!=1)
                              Text(dataMap['contractMode']=="DRIVER"?"货主待确认":"司机待确认",style: TextStyle(color: MyColors.themeColor,fontSize: 28.sp,fontWeight: FontWeight.w600),),
                            if(dataMap['contractStatus']==1&&dataMap['driverStatus']==0&&dataMap['deliveryStatus']==0&&dataMap['contractStatus']!=2&&dataMap['cancelStatus']!=1&&dataMap['cancelStatus']!=1)
                              Text("确认已装货",style: TextStyle(color: MyColors.themeColor,fontSize: 28.sp,fontWeight: FontWeight.w600),),
                            if(dataMap['contractStatus']==1&&dataMap['driverStatus']==1&&dataMap['deliveryStatus']==0&&dataMap['contractStatus']!=2&&dataMap['cancelStatus']!=1)
                              Text("确认已卸货",style: TextStyle(color: MyColors.themeColor,fontSize: 28.sp,fontWeight: FontWeight.w600),),
                            if(dataMap['deliveryStatus']==0&&dataMap['driverStatus']==2&&dataMap['contractStatus']!=2&&dataMap['cancelStatus']!=1)
                              Text("待货主完成",style: TextStyle(color: MyColors.themeColor,fontSize: 28.sp,fontWeight: FontWeight.w600),),
                            Icon(Icons.arrow_forward_ios,color: MyColors.themeColor,size: 20,),
                          ],
                        ),
                        onTap: (){
                          showModalBottomSheet(context: context, builder: (BuildContext context) {
                            return Container(
                              padding: EdgeInsets.only(left: 12.w,top: 15.h,right: 12.w,bottom: 40.h),
                              decoration: BoxDecoration(
                                  color: Colors.white,
                                  borderRadius: BorderRadius.all(Radius.circular(10))),
                              child: Column(
                                children: [
                                  Row(
                                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                    children: [
                                      SizedBox(width: 30.w,),
                                      Text("运单记录",style: TextStyle(color: Colors.black,fontSize: 18.sp),),
                                      IconButton(onPressed: (){
                                        Navigator.pop(context);
                                      }, icon: Icon(Icons.close,color: MyColors.textColor,size: 30,)),
                                    ],
                                  ),
                                  Divider(height: 16.h,color: MyColors.backgreyColor,),
                                  Container(
                                    height:280.h,

                                    child: ListView.builder(
                                        itemCount: orderLogList.length,
                                        itemBuilder: (context, index) {
                                          return Column(
                                            children: [
                                            Row(
                                            crossAxisAlignment: CrossAxisAlignment.start,
                                            children: [
                                              SizedBox(width: 18.w,),
                                              Icon(Icons.circle,color: index==0?MyColors.themeColor:MyColors.hintColor,size: 12,),
                                              SizedBox(width: 8.w,),
                                              Column(
                                                crossAxisAlignment: CrossAxisAlignment.start,
                                                mainAxisAlignment: MainAxisAlignment.start,
                                                children: [
                                                  Text(orderLogList[index]['description'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                                  Text(orderLogList[index]['createTime'],style: TextStyle(color: MyColors.authTipColor,fontSize: 12.sp),),

                                                ],
                                              ),
                                            ],
                                          ),
                                              SizedBox(height: 10.h,),
                                            ],
                                          );

                                        }
                                    ),
                                  ),
                                ],
                              ),
                            );
                          });
                        },
                      ),
                      Image.asset("lib/Images/OrderList/运单详情待确认收货icon.png",width: 50.w,height: 50.h,),
                    ],
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(left: 10.w,right: 10.w),
                  padding: EdgeInsets.only(left: 10.w,top: 5.h,right: 10.w,bottom: 5.h),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.all(Radius.circular(10))),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      if(dataMap['depositType']!=-1)
                      SizedBox(height: 8.h,),
                      if(dataMap['depositType']!=-1)
                      GestureDetector(
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Row(
                              children: [
                                BrnTagCustom.buildBorderTag(
                                  tagText: '订金',
                                  textColor: MyColors.themeColor,
                                  borderColor: MyColors.themeColor,
                                  borderWidth: 1,
                                  fontSize: 10.sp,
                                  textPadding: EdgeInsets.only(left: 4.w,right: 4.w),
                                ),
                                SizedBox(width: 4.w,),
                                Container(
                                  width:screenSize.width-100.w,
                                  child:dataMap['depositStatus']==0?Text("¥${(dataMap['deposit']).toString()}待司机支付",style: TextStyle(color: Colors.black,fontSize: 12.sp),):
                                  dataMap['depositStatus']==1? Text("¥${(dataMap['deposit']).toString()}平台监管中",style: TextStyle(color: Colors.black,fontSize: 12.sp),):
                                  dataMap['depositStatus']==2? Text("¥${(dataMap['deposit']).toString()}已退还司机",style: TextStyle(color: Colors.black,fontSize: 12.sp),):
                                  Text("¥${(dataMap['deposit']).toString()}支付到货主",style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                                )
                              ],
                            ),

                            Icon(Icons.arrow_forward_ios,size: 14,color: MyColors.authTipColor,),
                          ],
                        ),
                        onTap: (){
                          showModalBottomSheet(context: context,
                              isScrollControlled: true,
                              enableDrag: false,builder: (BuildContext context) {
                                return MoneyGoShowSheet(MoneyType: 1, depositList: depositLogList, freightList: freightLogList, dataMap: dataMap,);
                              });
                        },
                      ),
                      SizedBox(height: 8.h,),
                      GestureDetector(
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Row(
                              children: [
                                BrnTagCustom.buildBorderTag(
                                  tagText: '运费',
                                  textColor: MyColors.themeColor,
                                  borderColor: MyColors.themeColor,
                                  borderWidth: 1,
                                  fontSize: 10.sp,
                                  textPadding: EdgeInsets.only(left: 4.w,right: 4.w),
                                ),
                                SizedBox(width: 4.w,),
                                Text("¥"+(dataMap['freight']).toString(),style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                                Text(dataMap['freightStatus']==1?"支付到平台":dataMap['freightStatus']==2?"到司机账户":dataMap['freightStatus']==3?"退回到货主":dataMap['freightStatus']==-1?"线下支付":"待货主支付",style: TextStyle(color: Colors.black,fontSize: 12.sp),),

                              ],
                            ),

                            Icon(Icons.arrow_forward_ios,size: 14,color: MyColors.authTipColor,),
                          ],
                        ),
                        onTap: (){
                          showModalBottomSheet(context: context,
                              isScrollControlled: true,
                              enableDrag: false,builder: (BuildContext context) {

                                return MoneyGoShowSheet(MoneyType: 2,depositList: depositLogList, freightList: freightLogList, dataMap: dataMap,);
                              });
                        },
                      ),
                      SizedBox(height: 8.h,),
                      Text("货运信息",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                      SizedBox(height: 4.h,),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              Column(
                                children: [
                                  Image.asset("lib/Images/OrderList/装货点icon.png",width:20.w ,height:20.h,),
                                  Image.asset("lib/Images/OrderList/垂直虚线.png",width:18.w ,height:25.h,),
                                  if(dataMap['goodsInfo']['loadPlaceInfo'].length==2)
                                    Column(
                                      children: [
                                        Image.asset("lib/Images/OrderList/装货点icon.png",width:20.w ,height:20.h,),
                                        Image.asset("lib/Images/OrderList/垂直虚线.png",width:18.w ,height:25.h,),
                                      ],
                                    ),
                                  if(dataMap['goodsInfo']['unloadPlaceInfo'].length==2)
                                    Column(
                                      children: [
                                        Image.asset("lib/Images/OrderList/卸货点icon.png",width:20.w ,height:20.h,),
                                        Image.asset("lib/Images/OrderList/垂直虚线.png",width:18.w ,height:25.h,),
                                      ],
                                    ),
                                  Image.asset("lib/Images/OrderList/卸货点icon.png",width:20.w ,height:20.h,),
                                ],
                              ),

                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Row(
                                    children: [
                                      Container(
                                        constraints: BoxConstraints(
                                          // minWidth: 60.w,
                                          maxWidth:170.w, // 限制文本最大宽度
                                        ),
                                        child: Text(dataMap['goodsInfo']['loadPlaceInfo'][0]['city']+" "+dataMap['goodsInfo']['loadPlaceInfo'][0]['county'],style: TextStyle(color: Colors.black,fontSize: 14.sp),overflow: TextOverflow.ellipsis,),
                                      ),

                                      SizedBox(width: 8.w,),
                                      Container(
                                        constraints: BoxConstraints(
                                          // minWidth: 60.w,
                                          maxWidth:screenSize.width-240.w, // 限制文本最大宽度
                                        ),
                                        child:Text(dataMap['goodsInfo']['loadDay']+" "+dataMap['goodsInfo']['loadTime']+"点装货",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),overflow: TextOverflow.ellipsis,),
                                      ),


                                    ],
                                  ),
                                  Container(
                                    constraints: BoxConstraints(
                                      // minWidth: 60.w,
                                      maxWidth:screenSize.width-120.w, // 限制文本最大宽度
                                    ),
                                    child:   Text(dataMap['goodsInfo']['loadPlaceInfo'][0]['address'],style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),overflow: TextOverflow.ellipsis,),
                                  ),


                                  SizedBox(height: 8.h,),
                                  if(dataMap['goodsInfo']['loadPlaceInfo'].length==2)
                                    Column(

                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      children: [
                                        Container(
                                          constraints: BoxConstraints(
                                            // minWidth: 60.w,
                                            maxWidth:screenSize.width-120.w, // 限制文本最大宽度
                                          ),
                                          child:Text(dataMap['goodsInfo']['loadPlaceInfo'][1]['city']+" "+dataMap['goodsInfo']['loadPlaceInfo'][1]['county'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),

                                        ),
                                        Container(
                                          constraints: BoxConstraints(
                                            // minWidth: 60.w,
                                            maxWidth:screenSize.width-120.w, // 限制文本最大宽度
                                          ),
                                          child:   Text(dataMap['goodsInfo']['loadPlaceInfo'][1]['address'],style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),overflow: TextOverflow.ellipsis,),
                                        ),
                                      ],
                                    ),

                                  if(dataMap['goodsInfo']['unloadPlaceInfo'].length==2)
                                    Column(
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      children: [
                                        Container(
                                          constraints: BoxConstraints(
                                            // minWidth: 60.w,
                                            maxWidth:170.w, // 限制文本最大宽度
                                          ),
                                          child: Text(dataMap['goodsInfo']['unloadPlaceInfo'][0]['city']+" "+dataMap['goodsInfo']['unloadPlaceInfo'][0]['county'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                        ),
                                        Container(
                                          constraints: BoxConstraints(
                                            // minWidth: 60.w,
                                            maxWidth:screenSize.width-120.w, // 限制文本最大宽度
                                          ),
                                          child:  Text(dataMap['goodsInfo']['unloadPlaceInfo'][0]['address'],style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),overflow: TextOverflow.ellipsis,),
                                        ),
                                        SizedBox(height: 8.h,),
                                      ],
                                    ),
                                  Row(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    children: [
                                      Container(
                                        constraints: BoxConstraints(
                                          // minWidth: 60.w,
                                          maxWidth:170.w, // 限制文本最大宽度
                                        ),
                                        child:  dataMap['goodsInfo']['unloadPlaceInfo'].length==2?
                                        Text(dataMap['goodsInfo']['unloadPlaceInfo'][1]['city']+" "+dataMap['goodsInfo']['unloadPlaceInfo'][1]['county'],style: TextStyle(color: Colors.black,fontSize: 14.sp),)
                                            :Text(dataMap['goodsInfo']['unloadPlaceInfo'][0]['city']+" "+dataMap['goodsInfo']['unloadPlaceInfo'][0]['county'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                      ),


                                      SizedBox(width: 8.w,),
                                      if(dataMap['goodsInfo']['unloadDay']!=null)
                                        Container(
                                          constraints: BoxConstraints( 
                                            // minWidth: 60.w,
                                            maxWidth:screenSize.width-280.w, // 限制文本最大宽度
                                          ),
                                          child: Text(dataMap['goodsInfo']['unloadDay']+" "+dataMap['goodsInfo']['unloadTime']+"点卸货",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),overflow: TextOverflow.ellipsis,),
                                        ),

                                    ],
                                  ),

                                  Container(
                                    constraints: BoxConstraints(
                                      // minWidth: 60.w, 
                                      maxWidth:screenSize.width-120.w, // 限制文本最大宽度
                                    ),
                                    child:  dataMap['goodsInfo']['unloadPlaceInfo'].length==2?  Text(dataMap['goodsInfo']['unloadPlaceInfo'][1]['address'],style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),overflow: TextOverflow.ellipsis,):
                                    Text(dataMap['goodsInfo']['unloadPlaceInfo'][0]['address'],style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),overflow: TextOverflow.ellipsis,),
                                  )

                                ],
                              ),

                            ],
                          ),
                          Column(
                            children: [
                              GestureDetector(
                                child: Column(
                                  children: [
                                    Image.asset("lib/Images/OrderList/去装货地.png",width: 30.w,height: 30.h,),
                                    Text("去装货地",style: TextStyle(color: MyColors.themeColor,fontSize: 12.sp),),
                                  ],
                                ),
                                onTap: (){
                                  onOpenBaiduMapRoute(BMFOpenRouteType.TruckRoute);
                                },
                              ),
                              if(dataMap['goodsInfo']['loadPlaceInfo'].length==2)
                                SizedBox(height: 35.h,),
                              GestureDetector(
                                child: Column(
                                  children: [
                                    Image.asset("lib/Images/OrderList/去收货地.png",width: 25.w,height: 25.h,),
                                    Text("去卸货地",style: TextStyle(color: MyColors.themeColor,fontSize: 12.sp),),
                                  ],
                                ),
                                onTap: (){
                                  onOpenBaiduMapRouteUnload(BMFOpenRouteType.TruckRoute);
                                },
                              ),
                              if(dataMap['goodsInfo']['unloadPlaceInfo'].length==2)
                                SizedBox(height: 35.h,),
                            ],
                          ) ,

                        ],
                      ),

                      SizedBox(height: 8.h,),
                      GestureDetector(
                        child:Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Row(
                              children: [
                                Text("全程",style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                                Text(dataMap['goodsInfo']['distance']!=null?dataMap['goodsInfo']['distance']:"--",style: TextStyle(color: MyColors.themeColor,fontSize: 12.sp),),
                                Text("公里",style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                              ],
                            ),
                            Text("查看路线",style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                          ],
                        ),
                        onTap:(){
                          onOpenBaiduNaviNative(BMFNaviType.TruckNavi);
                        }
                      ),

                      Divider(height: 16.h,color: MyColors.backgreyColor,),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              Image.asset("lib/Images/OrderList/包裹icon.png",width: 24.w,height: 24.h,),
                              if(dataMap['goodsInfo']['cargoInfo'][0]['cargoWeight']!=null&&dataMap['goodsInfo']['cargoInfo'][0]['cargoVolume']!=null)
                                Text(dataMap['goodsInfo']['cargoInfo'][0]['cargoName']+"  "+dataMap['goodsInfo']['cargoInfo'][0]['cargoWeight'].toString()+"吨"+"  "+dataMap['goodsInfo']['cargoInfo'][0]['cargoVolume'].toString()+"方",style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                              if(dataMap['goodsInfo']['cargoInfo'][0]['cargoWeight']==null&&dataMap['goodsInfo']['cargoInfo'][0]['cargoVolume']!=null)
                                Text(dataMap['goodsInfo']['cargoInfo'][0]['cargoName']+"  "+"  "+dataMap['goodsInfo']['cargoInfo'][0]['cargoVolume'].toString()+"方",style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                              if(dataMap['goodsInfo']['cargoInfo'][0]['cargoWeight']!=null&&dataMap['goodsInfo']['cargoInfo'][0]['cargoVolume']==null)
                                Text(dataMap['goodsInfo']['cargoInfo'][0]['cargoName']+"  "+dataMap['goodsInfo']['cargoInfo'][0]['cargoWeight'].toString()+"吨"+"  ",style: TextStyle(color: Colors.black,fontSize: 12.sp),),

                            ],
                          ),
                          GestureDetector(
                            child:  Text("货物详情>",style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                            onTap: (){
                              showModalBottomSheet(context: context,
                                  isScrollControlled: true,
                                  enableDrag: false,builder: (BuildContext context) {

                                    return Container(
                                      height: 238.h,
                                      width: MediaQuery.of(context).size.width,
                                      padding: EdgeInsets.only(left: 18.w,right: 18.w,top: 15.h),
                                      decoration: BoxDecoration(
                                          color: Colors.white,
                                          borderRadius: BorderRadius.all(Radius.circular(10))),
                                      child: Column(
                                        children: [
                                          Row(
                                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                            children: [
                                              SizedBox(width: 30.w,),
                                              Text("货物详情",style: TextStyle(color: Colors.black,fontSize: 16.sp),),
                                              IconButton(onPressed: (){
                                                Navigator.pop(context);
                                              }, icon: Icon(Icons.close,size: 30,color: Colors.black,)),
                                            ],
                                          ),
                                          Divider(height: 16.h,color: MyColors.backgreyColor,),
                                          Row(
                                            children: [
                                              Text("货物",style: TextStyle(color: MyColors.textColor,fontSize: 14.sp),),
                                              SizedBox(width: 23.w,),
                                              Text(dataMap['goodsInfo']['cargoInfo'][0]['cargoName'],style: TextStyle(color:Colors.black,fontSize: 14.sp),),
                                            ],
                                          ),
                                          SizedBox(height: 15.h,),
                                          Row(
                                            children: [
                                              Text("车辆",style: TextStyle(color: MyColors.textColor,fontSize: 14.sp),),
                                              SizedBox(width: 23.w,),
                                              Text(dataMap['vehicleInfo']['vehicleLength'].toString()+"米,"+dataMap['vehicleInfo']['vehicleModel'],style: TextStyle(color:Colors.black,fontSize: 14.sp),),
                                            ],
                                          ),
                                          SizedBox(height: 15.h,),
                                          Row(
                                            children: [
                                              Text("备注",style: TextStyle(color: MyColors.textColor,fontSize: 14.sp),),
                                              SizedBox(width: 23.w,),
                                              Text(dataMap['remark']!=null?dataMap['remark']:"",style: TextStyle(color:Colors.black,fontSize: 14.sp),),
                                            ],
                                          ),

                                        ],
                                      ),
                                    );
                                  });
                            },
                          ),

                        ],
                      )
                    ],
                  ),
                ),

                if(dataMap['depositType']!=-1)
                  Container(
                    margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                    padding: EdgeInsets.only(left: 10.w,top:10.h,right:10.w,bottom: 10.h),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(10))),
                    child: Column(
                      children: [
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Row(
                              children: [
                                Text("订金",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                SizedBox(width: 6.w,),
                                BrnTagCustom(
                                  tagText:dataMap['depositType']==0? "可退":"不退还",
                                  textColor: Colors.white,
                                  fontSize: 9.sp,
                                  backgroundColor: Color.fromRGBO(239,160,82,1),
                                  textPadding:EdgeInsets.only(left: 4.w,right: 4.w),
                                  fontWeight: FontWeight.w600,
                                ),
                              ],
                            ),
                            Text("¥"+(dataMap['deposit']).toString(),style: TextStyle(color: Colors.black,fontSize: 13.sp),),
                          ],
                        ),
                        SizedBox(height:10.h ,),

                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text("订金",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                            if(dataMap['depositStatus']==1)
                              Row(
                                children: [
                                  Text("平台监管账户中",style: TextStyle(color:MyColors.textColor,fontSize: 12.sp),),
                                  Image.asset("lib/Images/OrderList/平台监管账户中icon.png",width: 17.w,height: 17.h,),
                                ],
                              ),
                            if(dataMap['depositStatus']==3)
                              Text("已支付到货主账户",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                            if(dataMap['depositStatus']==2)
                              Text("退款成功",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                            if(dataMap['depositStatus']==0)
                              Text("待支付",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                            Text("¥"+(dataMap['deposit']).toString(),style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                          ],
                        ),
                      ],
                    ),
                  ),
                Container(
                  margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                  padding: EdgeInsets.only(left: 10.w,top:10.h,right:10.w,bottom: 10.h),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.all(Radius.circular(10))),
                  child: Column(
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              Text("运费",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                            ],
                          ),
                          Text("¥"+(dataMap['freight']).toString(),style: TextStyle(color: Colors.black,fontSize: 13.sp),),
                        ],
                      ),
                      SizedBox(height:10.h ,),

                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("运费",style: TextStyle(color:MyColors.textColor,fontSize: 12.sp),),
                          if(dataMap['freightStatus']==1)
                            Row(
                              children: [
                                Text("平台监管账户中",style: TextStyle(color:MyColors.textColor,fontSize: 12.sp),),
                                Image.asset("lib/Images/OrderList/平台监管账户中icon.png",width: 17.w,height: 17.h,),
                              ],
                            ),
                          if(dataMap['freightStatus']==2)
                            Text("已支付到司机账户",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                          if(dataMap['depositStatus']==3)
                            Text("已退回到货主账户",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                          if(dataMap['depositStatus']==0)
                            Text("待支付",style: TextStyle(color:MyColors.textColor,fontSize: 12.sp),),
                          if(dataMap['depositStatus']==-1)
                            Text("线下支付",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                          Text("¥"+(dataMap['freight']).toString(),style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                        ],
                      ),
                      Divider(height: 16.h,color: MyColors.backgreyColor,),
                      GestureDetector(
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Text("查看运费修改记录",style: TextStyle(color: MyColors.textColor,fontSize: 13.sp),),
                            Icon(Icons.arrow_forward_ios,size: 14,color: MyColors.authTipColor,),
                          ],
                        ),
                        onTap: (){
                          NoLoadinggetApiManager.getData(
                            context,
                            "api/waybill/freight/change/page",
                            {'current':'1','size':20,"waybillId":dataMap['id']},
                                (responseData)  {
                                      showModalBottomSheet(context: context,
                                      isScrollControlled: true,
                                      builder: (BuildContext context) {
                                        return Container(
                                          height: 300.h,
                                          padding: EdgeInsets.only(top: 10.h,bottom: 20.h,left: 10.w,right: 10.w),
                                          decoration: BoxDecoration(
                                              color: Colors.white,
                                              borderRadius: BorderRadius.all(Radius.circular(10))),
                                          child: Column(
                                            children: [
                                              Row(
                                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                                children: [
                                                  SizedBox(width: 20.w,),
                                                  Text("修改记录",style: TextStyle(color: MyColors.textColor,fontSize: 16.sp,fontWeight: FontWeight.w600),),
                                                  GestureDetector(
                                                    child: Icon(Icons.close,color: MyColors.authTipColor,size: 30,),
                                                    onTap: (){
                                                      Navigator.pop(context);
                                                    },
                                                  ),
                                                ],
                                              ),
                                              Divider(height: 16.h,color: MyColors.backgreyColor,),
                                              Container(
                                                height:200.h,
                                                child: ListView.builder(
                                                    shrinkWrap:false,
                                                    itemCount:responseData['data']['records'].length+1,
                                                    itemBuilder: (BuildContext context, int index) {
                                                      return Container(
                                                        child: Column(
                                                          crossAxisAlignment: CrossAxisAlignment.start,
                                                          children: [

                                                            Row(
                                                              children: [
                                                                Icon(Icons.panorama_fisheye,color: MyColors.themeColor,size: 8,),
                                                                SizedBox(width: 15.w,),
                                                                Text(index==0?dataMap['freight']:responseData['data']['records'][index]['freight']+"元/趟",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                                              ],
                                                            ),
                                                            Row(
                                                              children: [
                                                                SizedBox(width: 23.w,),
                                                                Text(index==0?(dataMap['createTime']+"货主发货填写"):(responseData['data']['records'][index]['createTime']+responseData['data']['records'][index]['description']),style: TextStyle(color: MyColors.authTipColor,fontSize: 13.sp),),
                                                              ],
                                                            ),

                                                            SizedBox(height: 8.h,),
                                                          ],
                                                        ),
                                                      );}
                                                ),
                                              )
                                            ],
                                          ),
                                        );
                                      });
                            },
                          );

                        },
                      ),
                    ],
                  ),
                ),
                // Container(
                //   margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                //   padding: EdgeInsets.only(left: 10.w,top:10.h,right:10.w,bottom: 10.h),
                //   decoration: BoxDecoration(
                //       color: Colors.white,
                //       borderRadius: BorderRadius.all(Radius.circular(10))),
                //   child: Column(
                //     children: [
                //       Row(
                //         mainAxisAlignment: MainAxisAlignment.spaceBetween,
                //         children: [
                //           Row(
                //             children: [
                //               Text("技术服务费",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                //             ],
                //           ),
                //           Text("¥"+(dataMap['deposit']).toString(),style: TextStyle(color: Colors.black,fontSize: 13.sp),),
                //         ],
                //       ),
                //       SizedBox(height:10.h ,),
                //
                //       Row(
                //         mainAxisAlignment: MainAxisAlignment.spaceBetween,
                //         children: [
                //           Text("技术服务费",style: TextStyle(color:MyColors.textColor,fontSize: 12.sp),),
                //           if(dataMap['depositStatus']==2)
                //             Text("已支付",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                //           if(dataMap['depositStatus']==0)
                //             Text("待支付",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                //           Text("¥"+(dataMap['deposit']).toString(),style: TextStyle(color:MyColors.textColor,fontSize: 12.sp),),
                //         ],
                //       ),
                //     ],
                //   ),
                // ),
                GestureDetector(
                  child:  Container(
                    margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                    padding: EdgeInsets.only(left: 12.w,top:10.h,right:6.w,bottom: 9.h),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(10))),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            ClipRRect(
                              borderRadius: BorderRadius.circular(10.0), // 设置圆角半径
                              child: Image.network(
                                MyServiceUrl.imgHeader + dataMap['shipperInfo']['avatarPath'],
                                width: 36.w,
                                height: 36.h,
                                fit: BoxFit.cover, // 图片填充方式，可以根据需要调整
                              ),
                            ),
                            SizedBox(width: 13.w,),
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(dataMap['shipperInfo']['realName'],style: TextStyle(color: Colors.black,fontSize: 14.sp)),
                                Text(dataMap['shipperInfo']['phoneNum'],style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                              ],
                            ),
                          ],
                        ),
                        Row(
                          children: [
                            GestureDetector(
                              child: Image.asset("lib/Images/OrderList/IMicon.png",width: 24.w,height: 24.h,),
                              onTap: (){

                              },
                            ),
                            SizedBox(width: 8.w,),
                            GestureDetector(
                              child: Image.asset("lib/Images/OrderList/电话联系icon.png",width: 24.w,height: 24.h,),
                              onTap: (){
                                _makePhoneCall(dataMap['shipperPhone']);
                              },
                            ),
                          ],
                        )
                      ],
                    ),
                  ),
                  onTap: (){
                    Navigator.push( context, FadeRoute(page:ShipperIntroduction(shipperId: dataMap['shipperId'],)));
                  },
                ),

                GestureDetector(
                    child:  Container(
                      margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                      padding: EdgeInsets.only(left: 12.w,top:12.h,bottom: 12.h,right: 5.w),
                      decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.all(Radius.circular(10))),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("货物运输协议",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                          Row(
                            children: [
                              Text(dataMap['contractStatus']==0||dataMap['contractStatus']==2?"待签署":"已签",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                              Icon(Icons.arrow_forward_ios,size: 14,color: MyColors.hintColor,),
                            ],
                          )
                        ],
                      ),
                    ),
                    onTap: () async {
                      choosePageAct();
                      // if(dataMap['contractStatus']==0||dataMap['contractStatus']==2){
                      //   Navigator.push( context, FadeRoute(page:UnconfirmedTransportationAgreement(wayBillId: dataMap['id'], Type: 1,
                      //   )));
                      // }else{
                      //   Navigator.push( context, FadeRoute(page:TransportProtocolNodes(waybillId: dataMap['id'],
                      //   )));
                      // }
                    }
                ),
                if(dataMap['invoiceType']==1)
                GestureDetector(
                  child:  Container(
                    margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                    padding: EdgeInsets.only(left: 12.w,top:12.h,bottom: 12.h,right: 5.w),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(10))),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text("电子协议",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                        Row(
                          children: [
                            Text("查看和下载",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                            Icon(Icons.arrow_forward_ios,size: 14,color: MyColors.hintColor,),
                          ],
                        )
                      ],
                    ),
                  ),
                  onTap: (){

                  },
                ),
                GestureDetector(
                  child:  Container(
                    margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                    padding: EdgeInsets.only(left: 12.w,top:12.h,bottom: 12.h,right: 5.w),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(10))),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            Text("图片",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                            Text("（装卸图片、回单）",style: TextStyle(color: MyColors.textColor),),
                          ],
                        ),

                        Row(
                          children: [
                            Text("查看",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                            Icon(Icons.arrow_forward_ios,size: 14,color: MyColors.hintColor,),
                          ],
                        )
                      ],
                    ),
                  ),
                  onTap: (){
                    Navigator.push( context, FadeRoute(page:PictureManagement(type: 1, dataMap: dataMap,)));
                  },
                ),
                Container(
                  margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                  padding: EdgeInsets.only(left: 10.w,top:10.h,bottom: 10.h,right: 10.w),
                  decoration: BoxDecoration(
                      color: Color.fromRGBO(251, 236, 228, 1),
                      borderRadius: BorderRadius.all(Radius.circular(10))),
                  child: Text("为保障订单顺利成交及跟车人员（如有）人身安全，请您在实际装货前务必核实并承诺实际货物信息、司机、车辆与订单展示一致。如不一致，您应当拒绝交易，否则后果自负！",
                  style: TextStyle(color: Colors.black,fontSize: 11.sp),),
                ),
                Container(
                  margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                  padding: EdgeInsets.only(left: 12.w,top:12.h,bottom: 8.h,right: 9.w),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.all(Radius.circular(10))),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text("其他信息",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                      SizedBox(height: 8.h,),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("运单编号",style: TextStyle(fontSize: 12.sp,color: MyColors.textColor),),
                          Row(
                            children: [
                              Text(dataMap['id'],style: TextStyle(fontSize: 12.sp,color: MyColors.textColor),),
                              SizedBox(width: 8.w,),
                              GestureDetector(
                                child:  Text("复制",style: TextStyle(fontSize: 12.sp,color: MyColors.themeColor),),
                                onTap: (){
                                  _copyToClipboard(dataMap['id']);
                                },
                              ),
                            ],
                          )
                        ],
                      ),
                      SizedBox(height: 8.h,),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("下单时间",style: TextStyle(fontSize: 12.sp,color: MyColors.textColor),),
                          Text(dataMap['createTime'],style: TextStyle(fontSize: 12.sp,color: MyColors.textColor),),
                        ],
                      ),
                    ],
                  ),
                ),
      ],
            ),
            ),
            if(dataMap['cancelStatus']!=1)
            Container(
              padding: EdgeInsets.only(left: 20.w,top: 10.h,right: 20.w,bottom: 35.h),
              decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.all(Radius.circular(10))),
              child:
              Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children:[

                  if(dataMap['contractStatus']==0&&dataMap['contractMode']=="DRIVER")
                    GestureDetector(
                      child:  Container(
                          width: 75.w,
                          height: 25.h,
                          decoration: BoxDecoration(
                            color: MyColors.themeColor,
                            borderRadius: BorderRadius.circular(30.0),
                            border: Border.all(
                              color: MyColors.themeColor,
                              width: 1.0,
                            ),
                          ),
                          child: Center(child: Text("取消运单",style: TextStyle(fontSize: 13.sp,color: Colors.white,fontWeight: FontWeight.w600),),)
                      ),
                        onTap: () {
                          showDialog(
                              barrierDismissible: false,
                              context: context,
                              builder: (BuildContext context) {
                                return BrnDialog(
                                  titleText: "温馨提示",
                                  messageText: "是否确认取消当前协议？",
                                  actionsWidget: [
                                    TextButton(
                                      onPressed: () {
                                        Navigator.pop(context);
                                      },
                                      child: Text("取消",
                                        style: TextStyle(color: MyColors.textColor, fontSize: 14.sp),),
                                    ),
                                    TextButton(
                                      onPressed: () {
                                        getApiManager.getData(
                                          context, // 上下文对象，用于显示提示信息等
                                          'api/waybill/contract/refuse', // 您的API端点
                                          {"id": dataMap['contract']['id']}, // 查询参数，如果没有可以传递null
                                              (responseData) {
                                            BrnToast.show(
                                              "操作成功",
                                              context,
                                              duration: BrnDuration.short,
                                            );
                                            Navigator.pushReplacement(
                                              context,
                                              MaterialPageRoute(
                                                builder: (context) => TabbarView(pateIndex: 2,),
                                                fullscreenDialog: true,),
                                            );
                                          },
                                        );
                                      },
                                      child: Text("确认",
                                        style: TextStyle(color: MyColors.themeColor, fontSize: 14.sp),),
                                    ),
                                  ],
                                );
                              });
                        }
                    ),
                   
                  if(dataMap['contractStatus']==0&&dataMap['contractMode']=="DRIVER"&&dataMap['cancelStatus']!=1)
                    GestureDetector(
                      child:  Container(
                          margin: EdgeInsets.only(left: 8.w),
                          width: 75.w,
                          height: 25.h,
                          decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.circular(30.0),
                            border: Border.all(
                              color: MyColors.themeColor,
                              width: 1.0,
                            ),
                          ),
                          child: Center(child: Text("查看协议",style: TextStyle(fontSize: 13.sp,color: MyColors.themeColor,fontWeight: FontWeight.w600),),)
                      ),
                      onTap: ()  {
                        Navigator.push( context, FadeRoute(page:UnconfirmedTransportationAgreement(wayBillId: dataMap['id'], Type: 1,
                        )));
                      },
                    ),
                  if((dataMap['contractStatus']==0||dataMap['contractStatus']==2)&&dataMap['contractMode']=="SHIPPER")
                    GestureDetector(
                      child:  Container(
                          width: 75.w,
                          height: 25.h,
                          decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.circular(30.0),
                            border: Border.all(
                              color: MyColors.themeColor,
                              width: 1.0,
                            ),
                          ),
                          child: Center(child: Text("确认协议",style: TextStyle(fontSize: 13.sp,color: MyColors.themeColor,fontWeight: FontWeight.w600),),)
                      ),
                      onTap: ()  {
                        Navigator.push( context, FadeRoute(page:UnconfirmedTransportationAgreement(wayBillId: dataMap['id'], Type: 1,
                        )));
                      },
                    ),
                  if(dataMap['deliveryStatus']==0&&dataMap['driverStatus']==0&&dataMap['contractStatus']==1)
                    GestureDetector(
                      child:  Container(
                          width: 85.w,
                          height: 25.h,
                          decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.circular(30.0),
                            border: Border.all(
                              color: MyColors.themeColor,
                              width: 1.0,
                            ),
                          ),
                          child: Center(child: Text("确认已装货",style: TextStyle(fontSize: 13.sp,color: MyColors.themeColor,fontWeight: FontWeight.w600),),)
                      ),
                      onTap: ()  {
                        showDialog(
                            context: context,
                            builder: (BuildContext context) {
                              return upLpadCarphotoAlert(dataMap: dataMap, photoType: 1,);

                            }
                        );
                      },
                    ),
                  if(dataMap['deliveryStatus']==0&&dataMap['driverStatus']==1)
                    GestureDetector(
                      child:  Container(
                          width: 85.w,
                          height: 25.h,
                          decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.circular(30.0),
                            border: Border.all(
                              color: MyColors.themeColor,
                              width: 1.0,
                            ),
                          ),
                          child: Center(child: Text("确认已卸货",style: TextStyle(fontSize: 13.sp,color: MyColors.themeColor,fontWeight: FontWeight.w600),),)
                      ),
                      onTap: ()  {
                        showDialog(
                            context: context,
                            builder: (BuildContext context) {
                              return upLpadCarphotoAlert(dataMap: dataMap, photoType: 2,);

                            }
                        );
                      },
                    ),
                  if(dataMap['driverStatus']==2&&dataMap['deliveryStatus']==0)
                    GestureDetector(
                      child:  Container(
                          width: 75.w,
                          height: 25.h,
                          decoration: BoxDecoration(
                            color: MyColors.themeColor,
                            borderRadius: BorderRadius.circular(30.0),
                            border: Border.all(
                              color: MyColors.themeColor,
                              width: 1.0,
                            ),
                          ),
                          child: Center(child: Text(dataMap['receiptStatus']==0?'上传回单':"查看回单",style: TextStyle(fontSize: 13.sp,color: Colors.white,fontWeight: FontWeight.w600),),)
                      ),
                      onTap: ()  {
                        if(dataMap['receiptStatus']==0){
                          Navigator.push( context, FadeRoute(page:UploadPhotoPage(dataMap: dataMap, uploadType: 3,)));

                        }else{
                          Navigator.push( context, FadeRoute(page:PictureManagement(type: 1,dataMap: dataMap)));
                        }
                      },
                    ),
                  SizedBox(width: 10.w,),
                  if(dataMap['driverEvaluateStatus']==0&&(dataMap['driverStatus']==2||dataMap['deliveryStatus']==1))
                    GestureDetector(
                      child:  Container(
                          width: 75.w,
                          height: 25.h,
                          decoration: BoxDecoration(
                            color: MyColors.themeColor,
                            borderRadius: BorderRadius.circular(30.0),
                            border: Border.all(
                              color: MyColors.themeColor,
                              width: 1.0,
                            ),
                          ),
                          child: Center(child: Text("评价货主",style: TextStyle(fontSize: 13.sp,color: Colors.white,fontWeight: FontWeight.w600),),)
                      ),
                      onTap: ()  {
                        Navigator.push( context, FadeRoute(page:EvaluationPage(dataMap: dataMap,)));
                      },
                    ),

                ],
              )
              ,
            ),
          ],
        ),

      ),
    );
  }
}

class MoneyGoShowSheet extends StatefulWidget {
  const MoneyGoShowSheet({super.key, required this.MoneyType, required this.depositList, required this.freightList, required this.dataMap});
  final int MoneyType;
  final List depositList;
  final List freightList;
  final Map dataMap;
  @override
  State<MoneyGoShowSheet> createState() => _MoneyGoShowSheetState();
}

class _MoneyGoShowSheetState extends State<MoneyGoShowSheet> {
  int checkType=-1;
  List depositList=[];
   List freightList=[];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    checkType =widget.MoneyType;
    getDepositAct();
    getFreightAct();
  }
  void getDepositAct(){
    NoLoadinggetApiManager.getData(
      context,
      "api/pay/deposit/log/page",
      {'waybillId':widget.dataMap['id']},
          (responseData)  {
        setState(() {
          depositList=responseData['data']['records'];
        });

      },
    );
  }
  void getFreightAct(){
    NoLoadinggetApiManager.getData(
      context,
      "api/pay/freight/log/page",
      {'waybillId':widget.dataMap['id']},
          (responseData)  {
        setState(() {
      freightList=responseData['data']['records'];
        });

      },
    );
  }
  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;

    return Container(
        height: 500.h,
      decoration: BoxDecoration(
          color: MyColors.backgreyColor,
          borderRadius: BorderRadius.all(Radius.circular(10))),
      child: Column(
        children: [
          Container(
            padding: EdgeInsets.only(left: 12.w,top: 15.h,right: 12.w,),
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10))),
            child:  Row(

              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                SizedBox(width: 30.w,),
                Text("钱款去向",style: TextStyle(color: Colors.black,fontSize: 18.sp),),
                IconButton(onPressed: (){
                  Navigator.pop(context);
                }, icon: Icon(Icons.close,color: MyColors.textColor,size: 30,)),
              ],
            ),
          ),

    Container(
    padding: EdgeInsets.only(left: 12.w,top: 15.h,right: 12.w,),
    decoration: BoxDecoration(
    color: Colors.white,
    borderRadius: BorderRadius.all(Radius.circular(10))),
      child:Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          SizedBox(),
          GestureDetector(
            child: Column(
              children: [
                Text("订金",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                Container(width: 20.w,height: 2.h,color: checkType==1?MyColors.themeColor:Colors.white,),
              ],
            ),
            onTap: (){
              setState(() {
                checkType=1;
              });
            },
          ),
          GestureDetector(
            child: Column(
              children: [
                Text("运费",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                Container(width: 20.w,height: 2.h,color: checkType==2?MyColors.themeColor:Colors.white,),
              ],
            ),
            onTap: (){
              setState(() {
                checkType=2;
              });
            },
          ),
          SizedBox(),
        ],
      ),
    ),
          Container(
            margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10))),
            child: Column(
              children: [
            Container(
              height: 40.h,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.only(topLeft: Radius.circular(10),topRight: Radius.circular(10)),
            gradient: LinearGradient(
              begin: Alignment.topLeft,
              end: Alignment.bottomRight,
              colors: [Color.fromRGBO(253,252,248,1), Color.fromRGBO(251,236,228,1)],
            ),
          ),
              child:checkType==1?
              Row(
                children: [
                  SizedBox(width: 16.w,),
                  Icon(Icons.access_time_filled,color: MyColors.themeColor,),
                  SizedBox(width: 6.w,),
                  if(widget.dataMap['depositStatus']==1)
                  Text("支付到平台",style: TextStyle(color: MyColors.themeColor,fontSize: 16.sp),),
                  if(widget.dataMap['depositStatus']==2)
                    Text("到货主账户",style: TextStyle(color: MyColors.themeColor,fontSize: 16.sp),),
                  if(widget.dataMap['depositStatus']==3)
                    Text("已退回",style: TextStyle(color: MyColors.themeColor,fontSize: 16.sp),),
                  if(widget.dataMap['depositType']==-1)
                    Text("无订金",style: TextStyle(color: MyColors.themeColor,fontSize: 16.sp),),
                ],
              ): Row(
                children: [
                  SizedBox(width: 16.w,),
                  Icon(Icons.access_time_filled,color: MyColors.themeColor,),
                  SizedBox(width: 6.w,),
                  if(widget.dataMap['freightStatus']==1)
                    Text("支付到平台",style: TextStyle(color: MyColors.themeColor,fontSize: 16.sp),),
                  if(widget.dataMap['freightStatus']==2)
                    Text("到司机账户",style: TextStyle(color: MyColors.themeColor,fontSize: 16.sp),),
                  if(widget.dataMap['freightStatus']==0)
                    Text("待货主支付",style: TextStyle(color: MyColors.themeColor,fontSize: 16.sp),),
                  if(widget.dataMap['freightStatus']==3)
                    Text("退回到货主",style: TextStyle(color: MyColors.themeColor,fontSize: 16.sp),),
                  if(widget.dataMap['freightStatus']==-1)
                    Text("线下支付",style: TextStyle(color: MyColors.themeColor,fontSize: 16.sp),),
                ],
              ),
            ),
                SizedBox(height: 19.h,),
                checkType==1?
                Row(
                  children: [
                    SizedBox(width: 13.w,),
                    Text("订金：¥",style: TextStyle(color: Colors.black),),
                    Text((widget.dataMap['deposit']).toString(),style: TextStyle(color: Colors.black,fontSize: 18.sp),),
                  ],
                ):
                Row(
                  children: [
                    SizedBox(width: 13.w,),
                    Text("运费：¥",style: TextStyle(color: Colors.black),),
                    Text((widget.dataMap['freight']).toString(),style: TextStyle(color: Colors.black,fontSize: 18.sp),),
                  ],
                ),
              SizedBox(height: 18.h,),
              ],
            ),
          ),
          checkType==1?
          Container(
            margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
            padding: EdgeInsets.only(top: 22.h),
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10))),
            height:screenSize.width-30.h,
            child: ListView.builder(
                itemCount: depositList.length,
                itemBuilder: (context, index) {
                  return Column(
                    children: [
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          SizedBox(width: 18.w,),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              SizedBox(height: 4.h,),
                              Icon(Icons.circle,color: index==0?MyColors.themeColor:MyColors.hintColor,size: 12,),
                            ],
                          ),
                          SizedBox(width: 8.w,),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: [
                              Text(depositList[index]['description'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                              Text(depositList[index]['createTime'],style: TextStyle(color: MyColors.textColor,fontSize: 13.sp),),

                            ],
                          ),
                        ],
                      ),
                      SizedBox(height: 10.h,),
                    ],
                  );
                }
            ),
          ):
          Container(
            margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
            padding: EdgeInsets.only(top: 22.h),
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10))),
            height:screenSize.width-30.h,
            child: ListView.builder(
                itemCount: freightList.length,
                itemBuilder: (context, index) {
                  return  Column(
                    children: [
                    Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      SizedBox(width: 18.w,),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          SizedBox(height: 4,),
                          Icon(Icons.circle,color: index==0?MyColors.themeColor:MyColors.hintColor,size: 12,),

                        ],
                      ),
                      SizedBox(width: 8.w,),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          Text(freightList[index]['description'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                          Text(freightList[index]['createTime'],style: TextStyle(color: MyColors.textColor,fontSize: 13.sp),),
                        ],
                      )
                    ],
                  ),
                      SizedBox(height: 10.h,),
                    ],
                  );


                }
            ),
          ),
        ],
      ),
    );
  }
}

